export type pathOptions = {
  userId: string,
  appId: string,
  nodeId: string,
  jobId: string
};
/**
 * **************************
  studio
  └── userId
      ├── appId
      │   └── nodeId
      │       └── sim-result
      │           └── jobId-1
      └── logs
          └── appId
              └── nodeId
 ****************************/
export class StoragePath {

  static of = (ctx: pathOptions) => new StoragePath(ctx);

  private constructor(private ctx: pathOptions) { }

  getUserPath(): string {
    return `studio/${this.ctx.userId}`;
  }

  getAppPath() {
    return `${this.getUserPath()}/${this.ctx.appId}`;
  }

  getNodePath() {
    return `${this.getAppPath()}/${this.ctx.nodeId}`;
  }

  getAppLogPath(): string {
    return `${this.getUserPath()}/logs/${this.ctx.appId}`;
  }

  getNodeLogPath(): string {
    const appLogPath = this.getAppLogPath();
    return `${appLogPath}/${this.ctx.nodeId}`;
  }

  getSimulationPath(): string {
    return `${this.getUserPath()}/simulation`;
  }

  getJobLogPath(jobId: string): string {
    return `${this.getSimulationPath()}/logs/${jobId}.log`;
  }

  // 存放 job 运行过程中的同步文件
  getSimSyncPath(jobId: string) {
    return `${this.getSimulationPath()}/sync/${jobId}`;
  }

  getSimResultPath(jobId?: string) {
    return `${this.getSimulationPath()}/sim-result/${jobId || this.ctx.jobId}`;
  }
}